package com.five.service.impl;

import com.five.exception.BusinessException;
import com.five.mapper.AuthorMapper;
import com.five.pojo.Author;
import com.five.service.AuthorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AuthorServiceImpl implements AuthorService {
    @Autowired
    private AuthorMapper authorMapper;

    /**
     * 根据手机号查询作者信息
     * @param phone
     * @return
     */
    @Override
    public Author queryByPhone(String phone) {
        if (phone == null || phone.trim().length() == 0){
            throw new BusinessException("手机号不能为空");
        }
        return authorMapper.queryByPhone(phone);
    }

    /**
     * 根据邮箱查询作者信息
     * @param email
     * @return
     */
    @Override
    public Author queryByEmail(String email) {
        if (email == null || email.trim().length() == 0){
            throw new BusinessException("邮箱不能为空");
        }
        return authorMapper.queryByEmail(email);
    }

    /**
     * 根据登录信息ID查询作者信息
     * @param loginInfoId
     * @return
     */
    @Override
    public Author queryByLoginInfoId(Long loginInfoId) {
        if (loginInfoId == null){
            throw new BusinessException("登录信息ID不能为空");
        }
        return authorMapper.queryByLoginInfoId(loginInfoId);
    }

    /**
     * 新增作者信息
     * @param author
     */
    @Override
    public void insertAuthor(Author author) {
        if (author == null){
            throw new BusinessException("作者信息不能为空");
        }
        authorMapper.insert(author);
    }

    /**
     * 更新作者信息
     * @param author
     */
    @Override
    public void updateAuthor(Author author) {
        if (author == null){
            throw new BusinessException("作者信息不能为空");
        }
        authorMapper.update(author);
    }

    /**
     * 根据账号查询作者信息
     * @param account
     * @return
     */
    @Override
    public Author queryByAccount(String account) {
        if (account == null || account.trim().length() == 0){
            throw new BusinessException("账号不能为空");
        }
        return authorMapper.queryByAccount(account);
    }
}
